<%@ include file="/WEB-INF/views/taglib.jsp" %>

<h3>Role Form</h3>	
	<form:form id="form" method="post" modelAttribute="systemRoleForm"  cssClass="simpleForm" onsubmit="formSubmit()">
		<form:hidden path="systemRole.systemRoleId" />
		<form:hidden path="systemRole.active" />
		
	 	<div class="clear" style="height:1px">&nbsp;</div>
		<jsp:include page="/WEB-INF/views/message.jsp"></jsp:include>
	  	<fieldset>
	  		<legend>Role Info</legend>
			<aims:column cssErrorClass="error" path="systemRole.roleName" >
	  		<form:label path="systemRole.roleName">
	  			Role Name * 
	 		</form:label>
	  		<form:input path="systemRole.roleName" /> <form:errors path="systemRole.roleName"  cssClass="errorSimple" />	 
			</aims:column>
	  		<aims:column cssErrorClass="error" path="systemRole.section">
	  		<form:label path="systemRole.section">
	  			Section *
	 		</form:label>
	 		<form:select path="systemRole.section.sectionId" id="sectionId">
	 			<form:option value=""></form:option>
	 			<form:options items="${globalSection}" itemValue="sectionId" itemLabel="sectionName" />
	 		</form:select> <form:errors path="systemRole.section" cssClass="errorSimple"  />   
	  		</aims:column>
			<aims:column cssErrorClass="error" path="selSystemAccessRight" >
			<form:label path="systemAccessRight">
	  			Access Right * 
	 		</form:label>
	 		<form:select path="systemAccessRight" size="18" multiple="multiple" cssStyle="width:200px">
	  			<form:options items="${globalAccessRight}" itemValue="accessRightId" itemLabel="accessRightName" />
	  		</form:select>
	  		<a onclick="moveElements($('#systemAccessRight'),$('#selSystemAccessRight'))">>></a> 
	  		<a onclick="moveElements($('#selSystemAccessRight'),$('#systemAccessRight'))"><<</a>
	  		<form:select path="selSystemAccessRight" size="18" multiple="multiple" cssStyle="width:200px">
	  			<form:options items="${systemRoleForm.systemRole.systemAccessRights}" itemValue="accessRightId" itemLabel="accessRightName" />
	  		</form:select>
	  		<form:errors path="selSystemAccessRight"  cssClass="errorSimple" />
			</aims:column>
			</fieldset>
      <div class="action">
	  	<c:choose>
	  		<c:when test="${systemRoleForm.systemRole.systemRoleId==null}">
	  			<button type="submit" class="button positive positiveButton">
	  			Save
	  			</button>
	  			<a href="<c:url value="/role/search" />" class="button">Back</a>
	  		</c:when>
	  		<c:when test="${systemRoleForm.systemRole.systemRoleId!=null}">
  				<button type="submit"  class="button positive">
  				Update
  				</button>
  				<a href="<c:url value="/role/search" />" class="button">Back</a>
	  		</c:when>
	  	</c:choose>
	 </div>	
	</form:form>
	<script type="text/javascript">
		$(document).ready(function() {
			if($('#selSystemAccessRight option').length > 0)
			{
				$('#selSystemAccessRight option').each(
				function() {
					$('#systemAccessRight option[value="'+$(this).val()+'"]').remove();
					
				});	
			}
		});
		
		function formSubmit()
		{
			if($('#selSystemAccessRight option').length > 0) {
				$('#selSystemAccessRight option').each(
				  function() {
				   	$(this).attr('selected','selected'); 
				  }
				);
			}
		}
	</script>